//
//  XGHotCommentView.m
//  BSBuDeJie
//
//  Created by monkey on 2018/12/30.
//  Copyright © 2018 itcast. All rights reserved.
//

#import <Masonry/Masonry.h>

#import "UIImageView+Extension.h"

#import "XGTopicCellTopCommentView.h"

#import "XGTopCommentModel.h"
#import "XGUserModel.h"

@interface XGTopicCellTopCommentView ()

/// 头像
@property (nonatomic,strong) UIImageView *iconImageView;
/// 昵称
@property (nonatomic,strong) UILabel *nameLabel;
/// 最热评论
@property (nonatomic,strong) UILabel *topCommentLabel;

@end

@implementation XGTopicCellTopCommentView

#pragma mark - 解析模型

- (void)setTopCommentModel:(XGTopCommentModel *)topCommentModel
{
    _topCommentModel = topCommentModel;
    
    [self.iconImageView xg_setImageWithURLString:topCommentModel.user.profileImage placeHolder:kPlaceHolderImage];
    self.nameLabel.text = topCommentModel.user.userName;
    if (topCommentModel.content.length > 0) {
        self.topCommentLabel.text = topCommentModel.content;
    } else {
        self.topCommentLabel.text = @"[语音]";
    }
}

#pragma mark - 构造函数

- (instancetype)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame]) {
        [self setUpUI];
    }
    
    return self;
}

- (void)setUpUI
{
    // 添加子控件
    [self addSubview:self.iconImageView];
    [self addSubview:self.nameLabel];
    [self addSubview:self.topCommentLabel];
    
    // 设置自动布局
    [self.iconImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.equalTo(self);
        make.size.mas_equalTo(CGSizeMake(30, 30));
    }];
    
    [self.nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.iconImageView);
        make.left.equalTo(self.iconImageView.mas_right).offset(kMargin);
    }];
 
    [self.topCommentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.iconImageView.mas_bottom).offset(kMargin);
        make.left.equalTo(self.iconImageView);
        make.right.equalTo(self).offset(-kMargin);
        make.bottom.equalTo(self);
    }];
}

#pragma mark - 懒加载

- (UIImageView *)iconImageView
{
    if (_iconImageView == nil) {
        _iconImageView = [[UIImageView alloc] init];
        _iconImageView.layer.cornerRadius = 30 / 2;
        _iconImageView.layer.masksToBounds = YES;
        _iconImageView.backgroundColor = [UIColor whiteColor];
    }
    
    return _iconImageView;
}

- (UILabel *)nameLabel
{
    if (_nameLabel == nil) {
        _nameLabel = [UILabel labelWithText:@"测试文本" textColor:[UIColor darkGrayColor] font:12 textAlignment:NSTextAlignmentCenter];
    }
    
    return _nameLabel;
}

- (UILabel *)topCommentLabel
{
    if (_topCommentLabel == nil) {
        _topCommentLabel = [UILabel labelWithText:@"测试文本" textColor:[UIColor lightGrayColor] font:15 textAlignment:NSTextAlignmentLeft];
    }
   
    return _topCommentLabel;
}

@end
